package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.CropsBean;

/**
 * 农作物类型数据适配
 */
public class EdUpTypeadapter extends BaseAdapter {
    private Context context;
    private CropsBean cropsBean;
    private String [] dpType;
    public EdUpTypeadapter(Context context, CropsBean cropsBean) {
        this.context = context;
        this.cropsBean=cropsBean;
    }

    public EdUpTypeadapter(Context context,String [] dpType) {
        this.context = context;
        this.dpType=dpType;
    }
    private Handler handler;

    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    @Override
    public int getCount() {
        if(dpType!=null){
            return dpType.length;

        }else{
            return cropsBean.getV().getALLCROPS().size();
        }

    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_edupgh, parent, false);
            holder = new ViewHolder();
            holder.tv_cp_type=(TextView) convertView.findViewById(R.id.tv_edup_content);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(dpType!=null){
            holder.tv_cp_type.setText(dpType[position]);
        }else{
            holder.tv_cp_type.setText( cropsBean.getV().getALLCROPS().get(position).getCropTypeName());
        }
        return convertView;
    }

    private class ViewHolder{
        TextView tv_cp_type;
    }
}
